package com.cx.mall.demo.service.impl;

import com.cx.mall.demo.service.IGrpcCartService;
import com.cx.mall.proto.Cart;
import com.cx.mall.proto.RequestParam;
import com.cx.mall.proto.ResponseResult;
import com.cx.mall.proto.RpcSimpleGrpc;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.apache.catalina.connector.Response;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class GrpcCartServiceImpl implements IGrpcCartService {
    @GrpcClient("cart-grpc")
    private RpcSimpleGrpc.RpcSimpleBlockingStub simpleBlockingStub ;

    @Override
    public void deleteCart(List<Cart> carts) throws Exception {
        RequestParam requestParam = RequestParam.newBuilder().addAllCarts(carts).build();
        ResponseResult result = simpleBlockingStub.deleteCart(requestParam);
        if (result.getCode()== 1000)
        {
            throw  new Exception(result.getMessage());
        }
    }
}
